<?php


class Model_Hr_Uploadlog extends Zend_Db_Table_Abstract {

	protected $_name = 'manager_upload_file_log';
	
	public function getUploadlog( $idLog){
		
		$row = $this->fetchRow("`id_log` = ". $idLog);
		if(!$row) return false;
		return $row->toArray();		
		
		}
		
	public function addUploadlog( $idManager , $idStaff , $fileType , $fileName , $fileComment , $date , $time){
		
		$data = array(
			
         "id_manager" =>  $idManager ,
         "id_staff" =>  $idStaff ,
         "file_type" =>  $fileType ,
         "file_name" =>  $fileName ,
         "file_comment" =>  $fileComment ,
         "date" =>  $date ,
         "time" =>  $time 
	
			);
		$this->insert($data);
		
		}
		
	public function updateUploadlog(  $idLog ,  $idManager , $idStaff , $fileType , $fileName , $fileComment , $date , $time){
		$data = array(
			
         "id_manager" =>  $idManager ,
         "id_staff" =>  $idStaff ,
         "file_type" =>  $fileType ,
         "file_name" =>  $fileName ,
         "file_comment" =>  $fileComment ,
         "date" =>  $date ,
         "time" =>  $time 
	
			);
			
		$this->update($data,"`id_log` = ". $idLog);
		}
		
	public function deleteUploadlog( $idLog){
		
		$this->delete("`id_log` = ". $idLog);
		
		}	
	
	public function listAll(){
		
		$rows =$this->fetchAll("1","id_log DESC ");
		if(!$rows) return false;
		return $rows->toArray();			
		
		}	
	public function getLastUploadManager($idStaff){
		
		$row = $this->fetchRow("id_staff = {$idStaff}","id_log DESC");
		if(!$row) return false;
		return $row['id_manager'];
	}
	

	public function findUploadComm($fileName,$idStaff){
		
		$row = $this->fetchRow("`file_name` LIKE '{$fileName}' AND `id_staff` = {$idStaff}","id_log DESC");
		if(!$row) return false;
		return $row['file_comment'];
	}
	
	public function verifyFile($fileName,$idStaff){
		$data = array('verified' => 1);
		
		$this->update($data,"`file_name` LIKE '{$fileName}' AND `id_staff` = {$idStaff}");
		
	}
	public function fileVerifyStatus($fileName,$idStaff){
		$row = $this->fetchRow("`file_name` LIKE '{$fileName}' AND `id_staff` = {$idStaff}","id_log DESC");
		if(!$row) return false;
		return $row['verified'];
	}
	
	public function checkFileNeedVerify(){
		$rows = $this->fetchAll("verified IS NULL");
		if(empty($rows)) return false;
		return $rows->toArray();
	}
	
	public function listNeedVerifyStaff($arrStaff){
		$arrRes = array();
		
		foreach($arrStaff as $k => $v){
			$arrRes[] = $v['id_staff'];
		}
		
		return array_unique($arrRes,SORT_NUMERIC);
	}
}



?>